package Operations;

import Book.book;
import Book.bookList;
import java.util.Scanner;
//定义借阅书籍操作这个类重写实现接口中的work抽象方法
public class BorrowOperation implements Ioperations{
    @Override
    public void work(bookList bookList) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入你要借阅书籍的名字");
        String name=scanner.nextLine();
        int i=0;
        //用遍历的方式查询书架中是否存在输入的书名
        for (;i <bookList.getUseMount(); i++) {
            //用bookList已写的方法获取下标为i的书对象
            book book=bookList.getBooks(i);
            if(book.getName().equals(name)&&book.getIsBorrowed()==false){
                bookList.getBooks(i).setBorrowed(true);
                System.out.println("当前图书状态"+book);
                System.out.println("借阅书籍成功");
                return;
            }else if(book.getName().equals(name)&&book.getIsBorrowed()==true)
                System.out.println("很抱歉，该书已被借出了，请选择其他书籍");
            return;
        }

        System.out.println("抱歉该书不存在");
    }
}
